package com.example.management.service;


import com.example.management.mapper.InventoryMapper;
import com.example.management.pojo.Inbound;
import com.example.management.pojo.Inventory;
import com.example.management.pojo.Outbound;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Service
public class InventoryService {
    @Autowired
    InventoryMapper inventoryMapper;

    //新增item到入库表

    public int inbound(Inbound inbound) {
        int rowsAffected = inventoryMapper.inbound(inbound); // 插入 Inbound 表
        inventoryMapper.addInventory(inbound); // 插入 Inventory 表
        return rowsAffected;
    }
    //查询全部库存数据
    public List<Inventory> findAllInventory() {
        return inventoryMapper.findAllInventory();
    }
    //
    public List<Inventory> getInventoryByName(String itemName) {
        return inventoryMapper.findByName(itemName);
    }
    //
    public int updateInventory(Inventory inventory) {
        return inventoryMapper.updateInventory(inventory);
    }
    public int deleteInventory(Inventory inventory) {
        return inventoryMapper.deleteInventory(inventory);
    }

    public void outbound(Outbound outbound) {
        inventoryMapper.outbound(outbound); // 插入 出库表
        inventoryMapper.reduceCurrentQuantity(outbound); // 减少库存数量
    }
}
